<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

if(!function_exists('curl_request')) {
    //发送curl请求


    function curl_request($url , $type = false , $param = [] , $https = false) {

        //初始化请求
        $ch = curl_init($url);
        //调用curl_setopt()，设置请求选项
        if($type) {
            //true 发送post请求， false 默认发送get请求
            curl_setopt($ch,CURLOPT_POST , TRUE); //post请求 设置请求方式
            curl_setopt($ch,CURLOPT_POSTFIELDS , $param ); //设置请求参数
        }
        //如果是https请求，需要禁止从服务器端验证本地证书
        if($https) {
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER , false);
        }
        //发送请求，设置返回结果 字符串形式
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        //调用curl_exec()发送请求，获取结果
        $res = curl_exec($ch);
        if(!$res) {
            curl_error($ch);
            curl_errno($ch);
        }
        curl_close($ch); //关闭请求

        return $res;

    }


}